package com.sc.nft.dao;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.sc.nft.entity.vo.BoxCollectionEquityVO;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.BoxEquity;
import com.sc.nft.mapper.BoxEquityMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * (sc_box_equity)数据DAO
 *
 * @author Tangzehui
 * @since 2023-11-09 16:01:19
 * @description
 */
@Slf4j
@Repository
public class BoxEquityDao extends ServiceImpl<BoxEquityMapper, BoxEquity> {
    public Boolean saveList(List<BoxEquity> boxEquityList){
        if (CollectionUtil.isNotEmpty(boxEquityList)){
            return saveBatch(boxEquityList);
        }
        return false;
    }

    public Boolean deleteByBoxItemId(Long boxItemId){
        LambdaUpdateWrapper<BoxEquity> wrapper  = new LambdaUpdateWrapper<>();
        wrapper.eq(BoxEquity::getBoxItemId, boxItemId);
        return remove(wrapper);
    }
    public List<BoxEquity> getByBoxItemId(Long boxItemId){
        LambdaQueryWrapper<BoxEquity> wrapper  = new LambdaQueryWrapper<>();
        wrapper.eq(BoxEquity::getBoxItemId, boxItemId);
        List<BoxEquity> boxEquities = baseMapper.selectList(wrapper);
        return boxEquities;
    }

    /**
     * 根据盲盒id和藏品id返回 奖励数据
     * @param boxId
     * @param collectionId
     * @return
     */
    public List<BoxEquity> getByBoxIdAndCollectionId(Long boxId, Long collectionId){
        return baseMapper.getByBoxIdAndCollectionId(boxId,collectionId);
    }
    public List<BoxEquity> getEquityItem(List<Long> boxItemIdList){
        QueryWrapper<BoxEquity> wrapper  = new QueryWrapper<>();
        wrapper.in("box_item_id", boxItemIdList);
        return baseMapper.selectList(wrapper);
    }
    public List<BoxEquity> selectByBoxItemId(List<Long> boxItemIdList){
        return baseMapper.selectByBoxItemId(boxItemIdList);
    }
}